<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Enables the ability to use PHP functions as XSLT functions</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="xsltprocessor.importstylesheet.html">XSLTProcessor::importStylesheet</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="xsltprocessor.removeparameter.html">XSLTProcessor::removeParameter</a></div>
 <div class="up"><a href="class.xsltprocessor.html">XSLTProcessor</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="xsltprocessor.registerphpfunctions" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">XSLTProcessor::registerPHPFunctions</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.4)</p><p class="refpurpose"><span class="refname">XSLTProcessor::registerPHPFunctions</span> &mdash; <span class="dc-title">Enables the ability to use PHP functions as XSLT functions</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-xsltprocessor.registerphpfunctions-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> 
   <span class="methodname"><strong>XSLTProcessor::registerPHPFunctions</strong></span>
    ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$restrict</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   This method enables the ability to use PHP functions as XSLT functions
   within XSL stylesheets.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-xsltprocessor.registerphpfunctions-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">restrict</code></em></dt>

     <dd>

      <p class="para">
       Use this parameter to only allow certain functions to be called from 
       XSLT.
      </p>
      <p class="para">
       This parameter can be either a string (a function name) or an array of
       functions.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-xsltprocessor.registerphpfunctions-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-xsltprocessor.registerphpfunctions-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5421">
    <p><strong>Example #1 Simple PHP Function call from a stylesheet</strong></p>
    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOB<br /></span><span style="color: #DD0000">&lt;allusers&gt;<br />&nbsp;&lt;user&gt;<br />&nbsp;&nbsp;&lt;uid&gt;bob&lt;/uid&gt;<br />&nbsp;&lt;/user&gt;<br />&nbsp;&lt;user&gt;<br />&nbsp;&nbsp;&lt;uid&gt;joe&lt;/uid&gt;<br />&nbsp;&lt;/user&gt;<br />&lt;/allusers&gt;<br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xsl&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOB<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;<br />&lt;xsl:stylesheet&nbsp;version="1.0"&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:php="http://php.net/xsl"&gt;<br />&lt;xsl:output&nbsp;method="html"&nbsp;encoding="utf-8"&nbsp;indent="yes"/&gt;<br />&nbsp;&lt;xsl:template&nbsp;match="allusers"&gt;<br />&nbsp;&nbsp;&lt;html&gt;&lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Users&lt;/h2&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;table&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:for-each&nbsp;select="user"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;&lt;td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:value-of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select="php:function('ucfirst',string(uid))"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:for-each&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;<br />&nbsp;&nbsp;&lt;/body&gt;&lt;/html&gt;<br />&nbsp;&lt;/xsl:template&gt;<br />&lt;/xsl:stylesheet&gt;<br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xmldoc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$xsldoc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsl</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$proc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">XSLTProcessor</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerPHPFunctions</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">importStyleSheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsldoc</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">transformToXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmldoc</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div></div>

    </div>
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-xsltprocessor.registerphpfunctions-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        The <em><code class="parameter">restrict</code></em> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="xsltprocessor.importstylesheet.html">XSLTProcessor::importStylesheet</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="xsltprocessor.removeparameter.html">XSLTProcessor::removeParameter</a></div>
 <div class="up"><a href="class.xsltprocessor.html">XSLTProcessor</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
